<template>
	<view class="main-box" v-if="!isVerify">
		<view>
			<image id="form-box" mode="widthFix" class="bg-image" :src="imagePath + 'top.png'"></image>
			<view class="main-form-box">
				


				<!-- <xmly-submit-form :mobile="formData.mobile" :param="formData.param" :submit="formData.submit"
					:btnImg="imagePath + 'submit-btn.png'"></xmly-submit-form> -->

				<xmly-auto-get-mobile :mobile="formData.mobile" :param="formData.param" :submit="formData.submit"
					:baseImagePath="imagePath"
					:btnImg="imagePath + 'submit-btn.png'"></xmly-auto-get-mobile>
			</view>
			<!-- <image mode="widthFix" class="bg-image" :src="imagePath + 'bottom.png'"></image> -->
		</view>
		<goto-form-fix-btn :btnImg="imagePath + 'submit-btn.png'" :targetId="scrollToTargetId"
			:scrollTop="scrollTop"></goto-form-fix-btn>

		<xmly-right-fix :imagePath="imagePath"></xmly-right-fix>
	</view>
	<view v-else style="height: 100vh;display: flex;justify-content: center;align-items: center;color: #00000;">
		该功能暂未开通
	</view>


</template>

<script>
	import httpUtil from "@/utils/httpUtil";
	import userApi from "@/api/userApi.js"
	import ximaLayaShengHeApi from "@/api/ximaLayaShengHeApi";
	import commonApi from "@/api/commonApi";
	import validParamsUtil from "@/utils/validParamsUtil.js";
	import messageUtil from "@/utils/messageUtil.js"
	import logApi from "@/api/logApi";


	export default {
		data() {
			return {
				isVerify: false,
				scrollTop: 0,
				imagePath: 'https://h5.sx2b2c.com/images/tequan/ximalaya/tingchequan/version2/',
				scrollToTargetId: "form-box",
				formData: {
					mobile: '',
					param: '',
					submit: 0,
					intervalId: '',
				}				
			}
		},
		onLoad(option) {
			this.initData(option)
		},
		onShow() {
			this.checkOrderStatus()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		methods: {
			initData(option) {
				// option.a = 666666
				// option.param = 123
				// option.push_id = 456
				// option.pushid = 789
				// option.clickid = 234

				this.initParam(option)

				if (option.submit) {
					this.formData.submit = option.submit
				}

				userApi.getMiniLoginCode(code => {
					userApi.initUserId(code, res => {
						ximaLayaShengHeApi.buriedPoint(13)
					})
				})


				commonApi.isVerify(res => {
					this.isVerify = res
				})
				commonApi.is404()
				
			},
			initParam(option) {
				if (option.a) {
					httpUtil.setA(option.a)
				}
				if (option.param) {
					this.formData.param = option.param
					ximaLayaShengHeApi.setParam(option.param)
				}
				if (option.push_id) {
					this.formData.param = option.push_id
					ximaLayaShengHeApi.setParam(option.push_id)
				}
				if (option.pushid) {
					this.formData.param = option.pushid
					ximaLayaShengHeApi.setParam(option.pushid)
				}
				if (option.clickid) {
					this.formData.param = option.clickid
					ximaLayaShengHeApi.setParam(option.clickid)
				}
			},
			
			checkOrderStatus() {
				// this.formData.mobile = '13880104834'
				// this.formData.isSubmit = 1
				console.log('checkOrderStatus1')

				if (ximaLayaShengHeApi.getIsSubmit() && ximaLayaShengHeApi.getMobile()) {
					console.log('checkOrderStatus2')
					messageUtil.showLoading('订单确认中')
					this.formData.intervalId = setInterval(() => {
						this.checkOrderStatusHandler()
					}, 1500)

					setTimeout(() => {
						messageUtil.closeLoading()
						this.clearCheckOrderStatus()
					}, 10000)
				}
				console.log('checkOrderStatus3')
			},
			clearCheckOrderStatus() {
				if (this.formData.intervalId) {
					clearInterval(this.formData.intervalId)
					ximaLayaShengHeApi.removeIsSubmit()
					ximaLayaShengHeApi.removeMobile()
				}
			},
			checkOrderStatusHandler() {
				if (!validParamsUtil.validPhone(ximaLayaShengHeApi.getMobile())) {
					logApi.addLog('checkOrderStatusRequest,手机号不正确' + ximaLayaShengHeApi.getMobile())
					return;
				}

				let queryMobileParmas = {
					mobile: ximaLayaShengHeApi.getMobile()
				}
				logApi.addLog('checkOrderStatusRequest,检查订单是否支付，请求：' + JSON.stringify(queryMobileParmas))

				httpUtil.post('/api/xmly/queryMobile', queryMobileParmas, res => {
					logApi.addLog('checkOrderStatusRequest,检查订单是否支付，返回：' + JSON.stringify(res))
					if (res.data.sign) {
						this.clearCheckOrderStatus()
						uni.navigateTo({
							url: '/pages/xmly/xmly'
						})
					}
				})

			},

		}
	}
</script>

<style lang="scss">
	.main-box {
		background-color: #fa514a;
		min-height: 100vh;
		padding-bottom: 20rpx;
	}

	.main-form-box {
		width: 90%;
		// position: absolute;
		// left: 5%;
		// bottom: 10vh;
		margin: 10rpx auto 0;
	}

	.bg-image {
		width: 100%;
		height: auto;
	}

	
</style>